<template>
	<view class="detail">
		<detail-info :item="detali"></detail-info>
		<view class="uni-comment u-comment">
			<comment-list :comment="comment"></comment-list>
		</view>
		<!-- 输入框 -->
		<user-chat-bottom @submit="submit"></user-chat-bottom>
		<!-- 分享 -->
		<more-share :show="isshare" @shareshow="shareshow"></more-share>
	</view>
</template>

<script>
import detailInfo from '../../components/detail/detail-info.vue';
import settime from '../../common/time.js';
import commentList from '../../components/detail/comment-list.vue';
import userChatBottom from '../../components/user-chat/user-chat-bottom.vue';
import moreShare from '../../components/common/more-share.vue';
export default {
	data() {
		return {
			detali: '',
			isshare: false,
			comment: {
				count: 20,
				list: []
			}
		}
	},
	methods: {
		// 获取评论
		getcomment(){
			let arr = [
					{
						userpic: '../../static/demo/userpic/1.jpg',
						username: '小猫咪',
						time: '1590050375',
						data: '支持国产',
						fid: 0,
						id: 1
					},
					// 子级
					{
						userpic: '../../static/demo/userpic/1.jpg',
						username: '小猫咪',
						time: '1590050375',
						data: '支持国产',
						fid: 1,
						id: 2
					},
					{
						userpic: '../../static/demo/userpic/1.jpg',
						username: '小猫咪',
						time: '1590050375',
						data: '支持国产',
						fid: 1,
						id: 3
					},
					{
						userpic: '../../static/demo/userpic/1.jpg',
						username: '小猫咪',
						time: '1590050375',
						data: '支持国产',
						fid: 0,
						id: 1
					},
					{
						userpic: '../../static/demo/userpic/1.jpg',
						username: '小猫咪',
						time: '1590050375',
						data: '支持国产',
						fid: 1,
						id: 4
					},

			]
			for(let i = 0; i < arr.length; i++){
				arr[i].time = settime.gettime.gettime(arr[i].time);
			}
			this.comment.list = arr
		},
		// 初始化数据
		initdata(obj) {
			// 修改窗口标题
			this.detali = obj
			uni.setNavigationBarTitle({
				title:obj.title
			})
		},
		submit(data){
			let now = new Date().getTime();
			let obj = {
				userpic: '../../static/demo/userpic/1.jpg',
				username: '小猫咪',
				time: settime.gettime.gettime(now),
				data: '支持国产',
				fid: 0,
				id: 1
			};
			this.comment.list.push(obj)
		},
		shareshow() {
			this.isshare = !this.isshare
		}
	},
	onLoad(ev) {
		this.initdata(JSON.parse(ev.detailData))
		this.getcomment()
	},
	// 监听导航右边按钮
	onNavigationBarButtonTap(ev) {
		if(ev.index === 0){
			this.shareshow()
		}
	},
	components:{
		detailInfo,
		commentList,
		userChatBottom,
		moreShare
	}
}
</script>

<style scoped lang="scss">
.detail {
	width: 100%;
	padding-bottom: 120upx;
	box-sizing: border-box;
	position: relative;
	// 分享
	
	// 评论
	.u-comment {
		padding: 0 20upx;
		width: 100%;
		box-sizing: border-box;
	}
}
</style>
